/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */

/**
 * @param {ListNode} headA
 * @param {ListNode} headB
 * @return {ListNode}
 */
 var getIntersectionNode = function(headA, headB) {
    let pA= headA
    let pB = headB
    while(pA !== pB && pA && pB){
      if(pA.next){
        pA = pA.next
      }else{
        pA = headB
      }
      if(pB.next){
        pB = pB.next
      }else{
        pB = headA
      }
    }
    if(pA === null || pB === null) return null
    return pA
};